<?php
	$_products = $this->getProductCollection();
	$_helper = $this->helper('catalog/output');
	
	$limitproduct = $this->getLimitCount();
	$size = $_products->getSize();
	if($limitproduct == "" || $limitproduct > $size){
		$limitproduct = $size;
	}
	
	$w = $this->getThumbnailWidth();
	$h = $this->getThumbnailHeight();
	$_columnCount = $this->getColumnCount();
	$alt_img = $this->getAltImg();
	   
	   /* slider config */
	$idJs = "em_minifilter_products_".md5(uniqid(rand()));    
	   if ($this->getData('slider_unique_id'))
		$idJs = $this->getData('slider_unique_id');
	$this->idJs = $idJs;
    $idTab = "em_minifilter_products_tab_".md5(uniqid(rand()));
?>
<div id="<?php echo $idJs;?>" class="em-grid-12 <?php if($this->getCustomClass()): ?><?php echo $this->getCustomClass();?><?php endif; ?>">
	<?php if($this->getFrontendTitle()): ?>
		<div class="widget-title em-widget-title">
			<h3><span><?php echo $this->getFrontendTitle(); ?></span></h3>
		</div>
	<?php endif; ?>
    
	<?php if($this->getFrontendDescription()):?>
	<div class="desc"><?php echo $this->getFrontendDescription(); ?></div>
	<?php endif ?>
    
	<?php if ($limitproduct): ?>
	<div class="widget em-filterproducts-grid">
		<div id="<?php echo $idTab ?>" class="row">
			<div class="col-sm-10 first em-wrapper-tabs">
				<?php $i=0; foreach ($_products as $_product): ?>
				<div class="em-item-tabs" id="<?php echo $idTab ?>-<?php echo $i ?>">					
					<?php if ($this->getShowFrontend('thumb')): ?>
					<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="product-image">
						<?php if ($this->getShowFrontend('label') && Mage::helper('core')->isModuleEnabled('EM_Productlabels')):?>
						<!--show label product - label extension is required-->
						<?php Mage::helper('productlabels')->display($_product);?>
						<?php endif;?>
						<?php if ($alt_img): ?>
						<img class="em-alt-hover img-responsive" src="<?php echo $this->helper('catalog/image')->init($_product, $alt_img)->resize($w,$h) ?>" width="<?php echo $w; ?>" height="<?php echo $h ;?>" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />
						<?php endif ?>
						<img class="img-responsive <?php if ($alt_img): ?>em-alt-org<?php endif ?>" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($w,$h) ?>" width="<?php echo $w; ?>" height="<?php echo $h ;?>" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />                        
					</a>
					<?php else: ?>
					<?php if ($this->getShowFrontend('label') && Mage::helper('core')->isModuleEnabled('EM_Productlabels')):?>
					<!--show label product - label extension is required-->
					<?php Mage::helper('productlabels')->display($_product);?>
					<?php endif;?>
					<?php endif; ?>
					<div class="product-shop">
						<div class="f-fix">
							<!--product name-->
							<?php if ($this->getShowFrontend('name')):?>
							<h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></a></h3>
							<?php endif;?>
							<?php if ($this->getShowFrontend('sku')):?>
							<p class="sku"><?php echo $_product->getSku(); ?></p>
							<?php endif ;?>
							<!--product description-->
							<?php if ($this->getShowFrontend('desc')):
								$desc = $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description');
								if(strlen($desc)>80) {
									$strCutTitle = substr($desc, 0, 80);
									$desc = substr($strCutTitle, 0, strrpos($strCutTitle, ' '));
								}
								?>
							<p class="desc"><?php echo $desc; ?></p>
							<?php endif ;?>
							<!--product reviews-->
							<?php if ($this->getShowFrontend('review')):?>
							<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
							<?php endif ; ?>
							<!--product price-->
							<?php if ($this->getShowFrontend('price')):?>
							<?php if (Mage::helper('catalog')->canApplyMsrp($_product)):?>
							<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $this->__('Detail') ?></a>
							<?php else : ?>
							<?php echo $this->getPriceHtml($_product, true, "-emprice-".md5(uniqid(rand())) ) ?>
							<?php endif;?>
							<?php endif;?>
							<?php if($this->getShowFrontend('addtocart') || $this->getShowFrontend('addto')): ?>
							<div class="em-btn-addto">
								<!--product add to cart-->
								<?php if ($this->getShowFrontend('addtocart')):?>
								<?php if ($_product->isSaleable()): ?>
								<button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Add to Cart')) ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
								<?php else: ?>
								<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
								<?php endif; ?>
								<?php endif; ?>
								<!--product add to compare-wishlist-->
								<?php if($this->getShowFrontend('addto')):?>
								<ul class="add-to-links">
									<?php if ($this->helper('wishlist')->isAllow()) : ?>
									<li><a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-wishlist" title="<?php echo $this->__('Add to Wishlist') ?>"><?php echo $this->__('Add to Wishlist') ?></a></li>
									<?php endif; ?>
									<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
									<li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare" title="<?php echo $this->__('Add to Compare') ?>"><?php echo $this->__('Add to Compare') ?></a></li>
									<?php endif; ?>
								</ul>
								<?php endif; ?>
							</div>
							<?php endif;?>
						</div>
					</div>
					<?php 
	                        $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages();
	                        $_wThumbs = $w/4 - 10;
	                        $_hThumbs = $h/4 - 10; 
	                    ?>    
	                    
	                    <?php if (count($_images) > 0): ?>
	                    <div class="em-more-views row">
	                        <?php $j=0; foreach ($_images as $_image): ?>
	                        <?php 
	                            $_img_big = (string)$this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile()); 
	                            $_img_thumb = (string)$this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize($_wThumbs,$_hThumbs); 
	                        ?>
	                            <div class="col-sm-6" >
	                                <a class="em-thumb em_lightbox_<?php echo $idJs.$i?>" rel="gallery_<?php echo $idJs.$i?>" href="<?php echo $_img_big ?>#image<?php echo $idJs.$i ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
                                        <img class="img-responsive" src="<?php echo $_img_thumb ?>"  width="<?php echo $_wThumbs; ?>" height="<?php echo $_hThumbs ?>" alt="<?php echo $this->escapeHtml($_image->getLabel()) ?>"  />
	                                </a>
	                            </div>
	                        <?php if($j>=3) break;?>
	                        <?php $j++;?>
	                        <?php endforeach; ?>

	                    </div>
	                    <script type="text/javascript">
						//<![CDATA[						    
							    jQuery(".em_lightbox_<?php echo $idJs.$i ?>").fancybox({									
							    	margin: [20, 40, 20, 10],
									scrolling : 'no',
									type : 'image',
									nextEffect : 'none',
									prevEffect : 'none',
								});							
						//]]>
						</script>
	                    <?php endif; ?>
				</div>
				<?php $i++;?>
				<?php if($i >= $limitproduct) break;?>
				<?php endforeach; ?>
			</div>
			<ul class="col-sm-14 last tabs-control">
				<?php $j=0; foreach ($_products as $_product): ?>
				<li>
					<div class="product-thumb-tab">
    					<div class="product-thumb">
    						<a href="#<?php echo $idTab ?>-<?php echo $j ?>">
    	                        
    	                        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(250,250) ?>" width="250" height="250" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />
    	                        <span><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></span>
    	                    </a>
                        </div>
    					<!--product reviews-->
    						<?php if ($this->getShowFrontend('review')):?>
    						<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
    						<?php endif ; ?>
                        <!--product price-->
    					<?php if ($this->getShowFrontend('price')):?>
    						<?php if (Mage::helper('catalog')->canApplyMsrp($_product)):?>
    							<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $this->__('Detail') ?></a>
    						<?php else : ?>
    							<?php echo $this->getPriceHtml($_product, true, "-emprice-".md5(uniqid(rand())) ) ?>
    						<?php endif;?>
    					<?php endif;?>
    				</div>
                </li>
				<?php $j++;?>
				<?php if($j >= $limitproduct) break;?>                    
				<?php endforeach;?>
			</ul>
		</div>
	</div>
</div>
<script type="text/javascript">
	//<![CDATA[
	    jQuery('#<?php echo $idTab ?>').responsiveTabs({  	                                                  
	        activate: function(e, tab) {
	        	tab.tab[0].style.display = 'none';	        		        	
	        },    
	        deactivate: function(e, tab){
	        	tab.tab[0].style.display = 'inline-table';
	        },	        
	    });
	//]]>
</script>
<?php else:?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php endif; ?>